package com.ebelter.bodyfatscale.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * 表盘指针
 * Created by pan on 2018/3/19.
 */

public class PointerView extends View {

    private Paint mPointerPaint;
    private float defValue = 135;

    public PointerView(Context context) {
        super(context);
        initView(context);
    }

    public PointerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public PointerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {

        mPointerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        //去锯齿
        mPointerPaint.setAntiAlias(true);
        mPointerPaint.setColor(Color.WHITE);
        mPointerPaint.setStyle(Paint.Style.FILL);
        mPointerPaint.setStrokeWidth(3);
    }




    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        //画三角形指针
        drawTrianglePointer(canvas);
    }

    Path path = new Path();
    private void drawTrianglePointer(Canvas canvas) {


        path.moveTo(getWidth()/2, getHeight() / 2 - 8);
        path.lineTo(getWidth(), getHeight() / 2);
        path.lineTo(getWidth()/2, getHeight() / 2 + 8);
        path.close();
        //根据Path进行绘制，绘制三角形
        canvas.drawPath(path, mPointerPaint);
    }


}
